package cn.com.ejiakanghu.controller;

import cn.com.ejiakanghu.core.utils.RespUtil;
import cn.com.ejiakanghu.core.vo.BaseResult;
import cn.com.ejiakanghu.service.EnterpriseWeChatService;
import cn.com.ejiakanghu.service.NoticeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("notice")
public class NoticeController {

    private Logger logger = LoggerFactory.getLogger(NoticeController.class);
    @Autowired
    private NoticeService noticeService;
    @Resource
    private EnterpriseWeChatService enterpriseWeChatService;

    @RequestMapping("add")
    public BaseResult addOrderMsg(@RequestParam String id) {
        noticeService.addOrderMsg(id);
        return RespUtil.success("添加成功");
    }

    @RequestMapping("send")
    public void sendOrderMsg(@RequestParam Integer id,@RequestParam String rfid,@RequestParam String mac) {

        try {
            logger.info("播报器发送获取参数:{},{}",id,rfid);
            noticeService.send(id,rfid,mac);
        } catch (Exception e) {
            logger.error("播报器发送错误:{}",e);

        }
    }


    @RequestMapping("sendAllOrderMsg")
    public BaseResult sendAllOrderMsg(@RequestParam String rfid,@RequestParam String mac) {
        try {
            logger.info("播报机刷卡获得rfid:{}",rfid);
            noticeService.sendAllOrderMsg(rfid,mac);
           return RespUtil.success();

        } catch (Exception e) {
            logger.info("播报机刷卡错误:{},rfid为：{}",e,rfid);
            return RespUtil.fail(1000,e.toString());

        }
    }

    /**
     * 测试发送企业微信
     */
    @RequestMapping("/sendWechat")
    public void sendWechat(Integer missionId){
        enterpriseWeChatService.sendNotice(missionId);
    }
}
